package com.wechat.network.robot;

import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.swak.reactivex.transport.ExchangeChannel;
import com.swak.registry.URL;
import com.swak.utils.Nets;

public abstract class RobotChannel implements ExchangeChannel {

	private final Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();
	private final InetSocketAddress address;
	protected final RobotNetwork network;

	public RobotChannel(RobotNetwork network) {
		this.network = network;
		this.address = new InetSocketAddress(Nets.getLocalAddress(), 0);
	}

	@Override
	public URL url() {
		return null;
	}

	@Override
	public boolean isConnected() {
		return true;
	}

	@Override
	public void close() {
	}

	@Override
	public InetSocketAddress localAddress() {
		return address;
	}

	@Override
	public InetSocketAddress remoteAddress() {
		return address;
	}

	@Override
	public boolean hasAttribute(String key) {
		return this.attributes.containsKey(key);
	}

	@Override
	public Object getAttribute(String key) {
		return this.attributes.get(key);
	}

	@Override
	public void setAttribute(String key, Object value) {
		this.attributes.put(key, value);
	}

	@Override
	public void removeAttribute(String key) {
		this.attributes.remove(key);
	}
}
